package top.usts.springframework.common;

import top.usts.springframework.bean.UserService;
import top.usts.springframework.beans.BeansException;
import top.usts.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @description:
 * @author: CJ
 * @date: 2022/2/23
 */
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("userService".equals(beanName)){
            UserService userService = (UserService) bean;
            userService.setLocation("新上海");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("post process After initialization");
        return bean;
    }
}
